<!DOCTYPE html>
<html>
{include file="public/header"}
<body>
{include file="public/x-nav"}
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <a class="layui-btn" href="{:url('add')}"><i class="layui-icon"></i>添加文章</a>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>分类</th>
            <th>标题</th>
            <th>作者</th>
            <th>标签</th>
            <th>原创</th>
            <th>显示</th>
            <th>置顶</th>
            <th>推荐</th>
            <th>点击数</th>
            <th>发布时间</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name="list" id="item"}
        <tr>
            <td>{$item->id}</td>
            <td>{$item->category->cat_name}</td>
            <td>{$item->title}</td>
            <td>{$item->author}</td>
            <td>{$item->tags}</td>
            <td class="td-status">
                <span class="layui-btn layui-btn-normal layui-btn-mini {$item->getData('is_original')? '' : 'layui-btn-disabled'}">{$item->is_original}</span>
            </td>
            <td class="td-status">
                <span class="layui-btn layui-btn-normal layui-btn-mini {$item->getData('is_show')? '' : 'layui-btn-disabled'}">{$item->is_show}</span>
            </td>
            <td class="td-status">
                <span class="layui-btn layui-btn-normal layui-btn-mini {$item->getData('is_top')? '' : 'layui-btn-disabled'}">{$item->is_top}</span>
            </td>
            <td class="td-status">
                <span class="layui-btn layui-btn-normal layui-btn-mini {$item->getData('is_recommend')? '' : 'layui-btn-disabled'}">{$item->is_recommend}</span>
            </td>
            <td>{$item->click_number}</td>
            <td>{$item->release_time}</td>
            <td class="td-manage">
                <a title="编辑"  onclick="x_admin_show('编辑','ad_edit/id/{$item->id}')" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="del(this,'{$item->id}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    {php}echo $list->render() {/php}
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.post("{:url('ad_delete')}",{id:id},function(response){
                if(response.code === 200){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                }else{
                    layer.msg(response.msg, {icon: 5, time: 1000});
                }
            },'json');
        });
    }

</script>
</body>

</html>